<?php
/**
 * Created by PhpStorm.
 * User: 64423
 * Date: 2018/10/16
 * Time: 11:41
 */

namespace app\shop\model;


use think\Model;

class CollectModel extends Model
{
    protected $table = 'dp_collect';
    protected $pk = 'id';
    protected $field = true;


    //收藏
    public static function add($user_id=0,$art_id=0)
    {
        if(self::isHas($user_id,$art_id))
        {
            return 1;
        }else{
            return self::insert(['user_id'=>$user_id,'art_id'=>$art_id,'add_time'=>time()]);
        }
    }

    //取消收藏
    public static function del($user_id=0,$art_id=0)
    {
        return self::where('user_id',$user_id)->where('art_id',$art_id)->delete();

    }



    //是否已收藏
    public static function isHas($user_id,$art_id)
    {
        return self::where('user_id',$user_id)->where('art_id',$art_id)->find();
    }


}